package tedu.api.collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortPoint {
    public static void main(String[] args) {
        List<Point> list = new ArrayList<>();
        list.add(new Point(5,8));
        list.add(new Point(15,60));
        list.add(new Point(57,89));
        list.add(new Point(1,4));
        list.add(new Point(10,8));
        list.add(new Point(22,35));
        System.out.println("list----原始："+list);

        //自定义排序规则：
        Collections.sort(list, (o1,o2)-> o1.getX()-o2.getX());
        System.out.println("list----Collections排序："+list);

        /**
         * jdk1.8时，List集合自身提供了sort方法进行排序，方法中需要传入比较器
         */
        list.sort((o1, o2)->o1.getY()-o2.getY());
        System.out.println("list----List排序："+list);
    }
}
